package run;

import interact.MouseHander;
import processing.core.PApplet;
import processing.core.PConstants;
import processing.core.PImage;
import processing.core.PVector;
import processing.video.*;

public class Doodler extends PApplet {

	  Env e;
	private MouseHander m;
	Capture myCap;
	private CellMode curr_cellMode = CellMode.Line;
	public static Doodler instance;

	PImage b;
	

	  public void setup() {
		instance = this;
	    size(1000, 650, PConstants.P2D);
	    //rectMode(CENTER);
	    noStroke();
	    smooth();
	    background(255);
	    e = new Env(this);
		frameRate(30);
	    m = new MouseHander(this, e);
	    

//		b = loadImage("../img/figure.jpg");
//		b.filter(BLUR, 1);
//		b.filter(THRESHOLD, 0.75F);
//		image(b,0,0);
//		int[] imgPix = b.pixels;
//		for (int x = 0; x < b.width; x++) {
//			for (int y = 0; y < b.height; y++) {
//				int px = imgPix[(int) (b.width*y + x)];
//				if (px < -1) {
//					e.addFigurePoint(new PVector(x, y, 0));
//				}
//			}
//		}
	  }
	  
	  public void keyPressed() {
		  if (key == 's') {
			  Env.GLOBAL_REPULSE_CONST += 0.01;
		  }
		  if (key == 'a') {
			  Env.GLOBAL_REPULSE_CONST -= 0.01;
		  }
		  
		  if (key == 'f') {
			  cycleCellMode();
		  }
		  
		  System.out.println(Env.GLOBAL_REPULSE_CONST);
	  }
	  
	  public void draw() {
			
			
		  // initialize a few line cells (the guys who generate the drawing)
		  e.draw();

//		  image(myCap, 0, 0);
		  // how do we do collision detection...?
		  
		  // initialize some environmental stuff (gravitons)
		  
	  }
	  
	  

	public void cycleCellMode() {
		CellMode[] values = CellMode.values();
		
		int nextInd = 0;
		for (int i = 0; i < values.length; i++) {
			if (curr_cellMode.equals(values[i])) {
				nextInd = (i+1) % values.length;
				System.out.println("Cellmode: " + values[nextInd]);
				curr_cellMode = values[nextInd];
				return;
			}
		}
	}
	  
	public CellMode getCellMode() {
		return curr_cellMode;
	}
	
	public enum CellMode {
		Line, Figure, FigureLine
	}
	  
	  
}
